//引入模块
let express = require("express")();
let expressStatic = require("express-static");
let mysql = require("mysql");

const port = 8080;

//数据库配置
var sql = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '123456',
    database: 'chuanyue',
});
sql.connect();

//路由请求
//获取信息列表
express.get("/getList", (request, response) => {
    sql.query(`select id,img,title,introduce from chuanyue`, (error, data) => {
        response.send(data);
    })
})

//获取详情页
express.get("/details", (request, response) => {
    let id = request.query.id;
    sql.query(`select * from chuanyue where id=${id}`, (error, data) => {
        response.send(data);
    })
})


//静态请求
express.use(expressStatic(__dirname + '/传悦'));

console.log(`running at ${port}`);
express.listen(port);